package com.wpp.rpc;

import com.wpp.rpc.api.ComplexService;
import com.wpp.rpc.api.HelloService;
import com.wpp.rpc.service.ComplexServiceImpl;
import com.wpp.rpc.service.HelloServiceImpl;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.concurrent.CountDownLatch;

public class RpcServer {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(1);
        new RpcServer().start();
        latch.await();
    }

    private void start() {
        try {
            Registry registry = LocateRegistry.createRegistry(8888);

            HelloService helloService = new HelloServiceImpl();
            ComplexService complexService = new ComplexServiceImpl();


            registry.rebind("hello", helloService);
            registry.rebind("complex", complexService);

            System.out.println("RPC server is ready...");

        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}
